package com.leaderhr.fishshop.model.product;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;


/**
 * 商品类型
 * @author Linssen
 *
 */
@Entity
@Table(name="t_productType")
public class ProductType implements Serializable{

	private static final long serialVersionUID = 2231848635246372914L;
	/**类别ID**/
	private Integer id;
	/**类别名称**/
	private String name;
	/**备注，用于google搜索页面描述**/
	private String note;
	/**是否可见 0表示不可见，1表示可见**/
	private Integer visible;
	/**排序**/
	private Integer seq;
	/**子类别**/
	private Set<ProductType> children = new HashSet<ProductType>();
	/**所属父类**/
	private ProductType parent;
	
	public ProductType() {
		super();
	}
	@Id
	@Column(unique = true, nullable = false, length = 36)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=50,nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(length=200)
	public String getNote() {
		return note;
	}
	public void setNote(String note) {
		this.note = note;
	}
	@Column(nullable=false)
	public Integer getVisible() {
		return visible;
	}
	public void setVisible(Integer visible) {
		this.visible = visible;
	}
	@Column(nullable=false)
	public Integer getSeq() {
		return seq;
	}
	public void setSeq(Integer seq) {
		this.seq = seq;
	}
	//**级联刷新级联删除**//*
	@OneToMany(cascade={CascadeType.REFRESH,CascadeType.REMOVE},mappedBy="parent" )
	public Set<ProductType> getChildren() {
		return children;
	}

	public void setChildren(Set<ProductType> children) {
		this.children = children;
	}
	
	@JsonIgnore
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="parentid")
	public ProductType getParent() {
		return parent;
	}
	public void setParent(ProductType parent) {
		this.parent = parent;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProductType other = (ProductType) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
	
	
}
